#include<opencv2/opencv.hpp>
#include<iostream>

using namespace std;
using namespace cv;

int main()
{
    Mat srcImage = imread("../img/orange.jpg");
    if (srcImage.empty())
    {
        return -1;
    }
    imshow("原图", srcImage);
    Mat midImage, dstImage; // 临时变量和识别图
    // 转为灰度图
    cvtColor(srcImage, midImage, COLOR_RGB2GRAY);
    // 进行高斯模糊
    GaussianBlur(midImage, midImage, Size(9, 9), 2, 2);
    // 进行霍夫圆变换
    vector<Vec3f> circles;
    // 霍夫变换去检测灰度图中的圆
    HoughCircles(midImage, circles, HOUGH_GRADIENT, 2, 10, 100, 73, 80, 100); 
    for(auto i = 0; i < circles.size(); ++i ){
        Point center(circles[i][0], circles[i][1]);
        int radius = circles[i][2];
        circle(srcImage, center, radius, Scalar(255, 0, 0), 3, 8, 0);
    }
    imshow("橘子识别图", srcImage);
    waitKey(0);
    return 0;
}